package cn.kgc.ssm.controller;

import cn.kgc.ssm.pojo.AirQuality;
import cn.kgc.ssm.pojo.District;
import cn.kgc.ssm.service.AirService;
import cn.kgc.ssm.service.DistrictService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author 许京东
 * @Description
 * @date 2021/5/25 11:15
 */
@Controller
public class AirController {
        @Autowired
    AirService airService;
        @Autowired
    DistrictService districtService;

        @RequestMapping("Find")
      public String findAll(Model model,
                            @RequestParam(value = "districtId",required = false) Integer districtId,
                            @RequestParam(value = "pageNo",required = false,defaultValue = "1") Integer pageNo)
        {
            PageHelper.startPage(pageNo,3);

            model.addAttribute("districtId",districtId);

//                if (districtId!=null){
//                    PageHelper.orderBy("monitorTime desc");
//                }

            List<AirQuality> allAirInfo = airService.getAllAirInfo(districtId);
            PageInfo<AirQuality> pageInfo=new PageInfo<>(allAirInfo);
            model.addAttribute("pageInfo",pageInfo);
            List<District> allDistrict = districtService.getAllDistrict();
            model.addAttribute("allDistrict",allDistrict);
            return "find";
        }
/*


        @RequestMapping("six")
        public String cha(@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "districtId") Integer districtId,Model model){
            PageHelper.startPage(pageNo,3);
            List<AirQuality> allAirInfo = airService.getAllAirInfo(districtId);
            PageInfo<AirQuality> pageInfo=new PageInfo<>(allAirInfo);
            model.addAttribute("pageInfo",pageInfo);
            return "find";
        }
*/




}
